//
//  WYHomeHeaderView.m
//  Hangbag
//
//  Created by admin on 2018/2/9.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYHomeHeaderView.h"
#import "WYHomeBrandCell.h"
#import "WYDailySelectionCell.h"
#import "WYVacationCell.h"
#import "WYBanquetCell.h"
#import "WYBusinessOfficeCell.h"
#import "WYHomeHeaderModel.h"
#import "WYBagListModel.h"
#import "WYHomeModel.h"
#import "WYBagModel.h"
@interface WYHomeHeaderView()<UITableViewDelegate,UITableViewDataSource,SDCycleScrollViewDelegate>

@property (nonatomic,strong)UITableView *tableView;


@end



@implementation WYHomeHeaderView
-(void)setHeaderDataArray:(NSMutableArray *)headerDataArray
{
    _headerDataArray = headerDataArray;
    NSMutableArray *imageArray = [[NSMutableArray alloc]init];
    for (WYHomeHeaderModel *model in headerDataArray) {
        [imageArray addObject:model.img];
    }
    
    
    [self.scrollview setImageURLStringsGroup:imageArray];
    [self.tableView reloadData];
}
-(void)setDataArray:(NSMutableArray *)dataArray
{
    _dataArray = dataArray;
    
    [self.tableView reloadData];
}


-(instancetype)init
{
    if ([super init]) {
        [self setupViews];
        [self setTableViewHeaderView];
    }
    return self;
}

-(void)setupViews
{
    self.tableView=[[UITableView alloc]init];
    [self addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.mas_equalTo(0);
    }];
    self.tableView.delegate=self;
    self.tableView.dataSource=self;
    [self.tableView registerNib:[UINib nibWithNibName:@"WYHomeBrandCell" bundle:nil] forCellReuseIdentifier:@"WYHomeBrandCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"WYDailySelectionCell" bundle:nil] forCellReuseIdentifier:@"WYDailySelectionCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"WYVacationCell" bundle:nil] forCellReuseIdentifier:@"WYVacationCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"WYBanquetCell" bundle:nil] forCellReuseIdentifier:@"WYBanquetCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"WYBusinessOfficeCell" bundle:nil] forCellReuseIdentifier:@"WYBusinessOfficeCell"];
    
    
}
-(void)setTableViewHeaderView
{
    UIView *view = [[UIView alloc]init];
    view.frame = CGRectMake(0, 0, kScreenWidth, kScreenWidth/2);
    // 网络加载 --- 创建带标题的图片轮播器
    SDCycleScrollView *cycleScrollView3 = [SDCycleScrollView cycleScrollViewWithFrame:view.bounds delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]];
    self.scrollview = cycleScrollView3;
    cycleScrollView3.currentPageDotImage = [UIImage imageNamed:@"pageControlCurrentDot"];
    cycleScrollView3.pageDotImage = [UIImage imageNamed:@"pageControlDot"];
  //  cycleScrollView3.imageURLStringsGroup = imagesURLStrings;
    
    [view addSubview:cycleScrollView3];
    
    self.tableView.tableHeaderView = view;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==0) {
        WYHomeBrandCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WYHomeBrandCell" forIndexPath:indexPath];
        if (!cell) {
            cell =[[NSBundle mainBundle]loadNibNamed:@"WYHomeBrandCell" owner:nil options:nil].firstObject;
        }
        cell.backgroundColor = [UIColor redColor];
        if (self.dataArray.count) {
            WYBagListModel *model = self.dataArray[0];
            cell.dataArray = model.bagthinks;
            cell.titleLabel.text = model.title;
        }
        
        
        return cell;
    }
   
    
    
    
    if (indexPath.row==1) {
        WYDailySelectionCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WYDailySelectionCell" forIndexPath:indexPath];
        if (!cell) {
            cell=[[NSBundle mainBundle] loadNibNamed:@"WYDailySelectionCell" owner:nil options:nil].firstObject;
        }
        if (self.dataArray.count) {
            WYBagListModel *model = self.dataArray[1];
            cell.titleLabel.text = model.title;
        }
        
        return cell;
    }
    if (indexPath.row==2) {
        WYVacationCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WYVacationCell" forIndexPath:indexPath];
        if (!cell) {
            cell=[[NSBundle mainBundle] loadNibNamed:@"WYVacationCell" owner:nil options:nil].firstObject;
        }
        if (self.dataArray.count) {
            WYBagListModel *model = self.dataArray[1];
            WYHomeModel *homeModel = model._child[0];
            cell.titleLabel.text = homeModel.title;
            WYBagModel *model1  =homeModel.bagthinks[0];
            [cell.leftImageView sd_setImageWithURL:[NSURL URLWithString:model1.img] placeholderImage:nil];
            WYBagModel *model2  =homeModel.bagthinks[1];
            [cell.topImageView sd_setImageWithURL:[NSURL URLWithString:model2.img] placeholderImage:nil];
            WYBagModel *model3  =homeModel.bagthinks[2];
            [cell.bootomImageView sd_setImageWithURL:[NSURL URLWithString:model3.img] placeholderImage:nil];
            
        }
        return cell;
    }
    if (indexPath.row==3) {
        WYBanquetCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WYBanquetCell" forIndexPath:indexPath];
        if (!cell) {
            cell=[[NSBundle mainBundle] loadNibNamed:@"WYBanquetCell" owner:nil options:nil].firstObject;
        }
        
        if (self.dataArray.count) {
            WYBagListModel *model = self.dataArray[1];
            WYHomeModel *homeModel = model._child[1];
            cell.titleLabel.text = homeModel.title;
            WYBagModel *model1  =homeModel.bagthinks[0];
            [cell.leftImageView sd_setImageWithURL:[NSURL URLWithString:model1.img] placeholderImage:nil];
            WYBagModel *model2  =homeModel.bagthinks[1];
            [cell.topImageView sd_setImageWithURL:[NSURL URLWithString:model2.img] placeholderImage:nil];
            WYBagModel *model3  =homeModel.bagthinks[2];
            [cell.bootomImageView sd_setImageWithURL:[NSURL URLWithString:model3.img] placeholderImage:nil];
            WYBagModel *model4  =homeModel.bagthinks[3];
            [cell.lastImageView sd_setImageWithURL:[NSURL URLWithString:model4.img] placeholderImage:nil];
        }
        
        
        
        
        
        return cell;
    }
    if (indexPath.row==4) {
        WYBusinessOfficeCell *cell =[tableView dequeueReusableCellWithIdentifier:@"WYBusinessOfficeCell" forIndexPath:indexPath];
        if (!cell) {
            cell=[[NSBundle mainBundle]loadNibNamed:@"WYBusinessOfficeCell" owner:nil options:nil].firstObject;
        }
        if (self.dataArray.count) {
            WYBagListModel *model = self.dataArray[1];
            WYHomeModel *homeModel = model._child[2];
            cell.titleLabel.text = homeModel.title;
            WYBagModel *model1  =homeModel.bagthinks[0];
            [cell.leftImageView sd_setImageWithURL:[NSURL URLWithString:model1.img] placeholderImage:nil];
            WYBagModel *model2  =homeModel.bagthinks[1];
            [cell.topImageView sd_setImageWithURL:[NSURL URLWithString:model2.img] placeholderImage:nil];
            WYBagModel *model3  =homeModel.bagthinks[2];
            
            WYBagModel *model4  =homeModel.bagthinks[3];
            [cell.lastImageView sd_setImageWithURL:[NSURL URLWithString:model3.img] placeholderImage:nil];
            [cell.bootomImageView sd_setImageWithURL:[NSURL URLWithString:model4.img] placeholderImage:nil];
        }
        return cell;
    }
 
    WYHomeBrandCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WYHomeBrandCell" forIndexPath:indexPath];
    if (!cell) {
        cell =[[NSBundle mainBundle]loadNibNamed:@"WYHomeBrandCell" owner:nil options:nil].firstObject;
    }
    cell.backgroundColor = [UIColor redColor];
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==1) {
        return 61;
    }
    if (indexPath.row==2) {
        return 240;
    }
    if (indexPath.row==3) {
        return 240;
    }
    if (indexPath.row==4) {
        return 240;
    }
    return 160;
}

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    NSLog(@"点击了%ld张图片",index);
}




@end
